// ============================== 导入依赖 ============================== //

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  async remoteInfo({ state: { API, infoParam } }) {
    const typeList = await API.getType(infoParam, API.transTip('查询通行统计'))
    const rankList = await API.getRank(infoParam, API.transTip('查询累计出入'))
    const tempObj = await API.getTemp(infoParam, API.transTip('查询体温统计'))

    return {
      in: transType(typeList, 'in'),
      out: transType(typeList, 'out'),
      temp: transTemp(tempObj),
      rank: transRank(rankList),
    }
  },
}

// ============================== 转换方法 ============================== //

const transType = (typeList, type) => {
  const matched = typeList.find((item) => item.name === type) || {}
  const list = matched.infos || []
  const inner = list.find((item) => item.name === 'Internal') || {}
  const visitor = list.find((item) => item.name === 'visitor') || {}

  return {
    xData: [inner.label || '内部人员', visitor.label || '访客'],
    dataList: [+inner.value || 0, +visitor.value || 0],
  }
}

const transTemp = ({ normals, abnormals }) => {
  return {
    dataList: [normals || 0, abnormals || 0],
  }
}

const transRank = (rankList) => {
  return rankList.map((item, i) => [i + 1, item.label || '-', +item.value])
}
